#include "frame_spec_test.h"

#include "dag.h"

#include <fstream>
#include <memory>

using namespace std;
using namespace dag;

namespace {
	const char* n_description = "frame_spec_test";
	const char* n_temp_file = "frame_spec_test.temp";
}

const char* FrameSpecTest::description() {
	return n_description;
}

bool FrameSpecTest::run() {
	
	try {
		if (FrameSpec() != FrameSpec()) {
			return false;
		}
		
		FrameSpec f1(1, 2, 3, 4);
		FrameSpec f2(4, 3, 2, 1);
		
		if (f1 == f2) {
			return false;
		}
		
		f2.bSize = 1;
		f2.iSize = 2;
		f2.fSize = 3;
		f2.dSize = 4;
		
		if (f1 != f2) {
			return false;
		} else if (!(f1 == f2)) {
			return false;
		}
		
		ofstream ofs(n_temp_file, ios::out | ios::trunc | ios::binary);
		f2.serialize(ofs);
		ofs.close();
		
		
		auto_ptr<FrameSpec> f3(NULL);
		ifstream ifs(n_temp_file, ios::binary);
		f3 = FrameSpec::inflate(ifs);
		if (f3.get() == NULL) {
			return false;
		}
		
		if (f1 != *f3) {
			return false;
		}
	}
	catch (...) {
		return false;
	}
	
	return true;
}